package ipWhite

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/ipwhite"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/rpc"
	"github.com/zeromicro/go-zero/core/logc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateIpWhiteStatusLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 修改状态
func NewUpdateIpWhiteStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateIpWhiteStatusLogic {
	return &UpdateIpWhiteStatusLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateIpWhiteStatusLogic) UpdateIpWhiteStatus(req *types.UpdateIpWhiteStatusReq) (resp *types.Empty, err error) {
	if req.Id == 0 {
		return nil, code.BusinessFailure
	}
	u, err := l.svcCtx.SettingService.IpWhite.UpdateIpWhiteStatus(l.ctx, &ipwhite.UpdateIpWhiteStatusReq{
		MerchantId: 1, // 商户ID
		Id:         req.Id,
		Status:     rpc.StatusType(req.Status),
	})

	if err != nil {
		logc.Error(l.ctx, "UpdateIpWhiteStatus err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}
	resp = &types.Empty{}
	return
}
